Page({
  data: {
    value:'',
    movies:[],
    placeholder:'',
    isSearch:false
  },
  
  saveInput(e){
    const value = e.detail.value
    this.setData({
      value
    })
  },
  //搜索事件
  search(){
    let _this = this
    let value = this.data.value
    wx.request({
      url: `https://m.maoyan.com/ajax/search?kw=${value}&cityId=1&stype=-1`,
      success(res){
        let movies = res.data.movies ? res.data.movies.list : []
        movies = movies.map(item => {
          item.img = item.img.replace('w.h','128.180')
          return item
        })
        _this.setData({
          movies,
          isSearch:true
        })
      }
    })
  },
  //重置、一键删除
  clear(){
    this.setData({
      movies:[],
      isSearch:false,
      value:null
    })
  }
})